package com.basic.business.labelMapping.service.impl;

import com.basic.business.labelMapping.domain.TLabelMapping;
import com.basic.business.labelMapping.mapper.TLabelMappingMapper;
import com.basic.business.labelMapping.service.ITLabelMappingService;
import com.basic.common.core.domain.entity.SysUser;
import com.basic.common.core.domain.entity.SysUserInfo;
import com.basic.common.core.service.impl.BaseServiceImpl;
import com.basic.system.mapper.SysUserMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 * 商品标签映射管理Service业务层处理
 *
 * @author zhaoxy_jn@163.com
 */
@Service
public class TLabelMappingServiceImpl extends BaseServiceImpl<TLabelMappingMapper, TLabelMapping> implements ITLabelMappingService {

    @Resource
    private TLabelMappingMapper tLabelMappingMapper;

    @Resource
    private SysUserMapper sysUserMapper;

    @Override
    public void importFileData(List<TLabelMapping> list) {

        for (TLabelMapping tLabelMapping : list){
            //没有的添加，有的不动
            int exist = tLabelMappingMapper.isExist(tLabelMapping.getMainLabel(), tLabelMapping.getSubLabel());
            if (exist == 0){
                //通过主标签获取用户信息
                SysUserInfo user = sysUserMapper.getUserInfoByGoodsLabel(tLabelMapping.getMainLabel());
                if (user != null){
                    tLabelMapping.setId(null);
                    tLabelMapping.setMainId(user.getUserId());
                    tLabelMappingMapper.insert(tLabelMapping);
                }
            }
        }
    }
}
